package com.jymj.utils.FileUtile;

import com.jymj.utils.PropertiesUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.system.ApplicationHome;

import java.io.File;


/**
 * 路径拼接工具
 *
 * @author Lzh
 * @date 2021/7/16 10:33
 */
@Slf4j
@Accessors(chain = true)
@Data
public class PathUtiles {
    public String path;
    public String url;
    public String pathHead;


    public PathUtiles PathUtilesInit(String setPath) {
        PropertiesUtil pathConfig = new PropertiesUtil("filePath.properties");
        pathHead = pathConfig.readProperty(setPath);
        url = pathConfig.readProperty("urlHead") + pathHead;
        path = System.getProperty("user.dir")+File.separator+"fileupload";
        ApplicationHome home = new ApplicationHome(getClass());
//        File jarFile = home.getSource();
//        File homeFile = home.getDir();
//        log.info("jarFile:{}",jarFile);
//        log.info("homeFile:{}",homeFile);
        log.info("初始化路径完成：" + path);
        log.info("初始化url完成：" + url);
        return new PathUtiles().setPath(path).setUrl(url).setPathHead(pathHead);
    }

    public String getUrl() {
        return url;
    }

    public String getPath() {
        return path;
    }

    public String getPathHead() {
        return pathHead;
    }

}
